package com.yulan.fastkillcourse.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.yulan.fastkillcourse.model.Course;
import com.yulan.fastkillcourse.model.CourseOrder;
import com.yulan.fastkillcourse.model.TeacherCourse;
import com.yulan.fastkillcourse.result.CodeMsg;
import com.yulan.fastkillcourse.result.Result;
import com.yulan.fastkillcourse.service.*;
import org.modelmapper.ModelMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 教师操作的controller
 */
@RestController
@RequestMapping("teacher")
public class TeacherController {

    @Autowired
    CourseService courseService;

    @Autowired
    CourseMarginService courseMarginService;

    @Autowired
    CourseTrackService courseTrackService;

    @Autowired
    CourseDiscussService courseDiscussService;

    @Autowired
    CourseOrderService courseOrderService;

    @Autowired
    TeacherCourseService teacherCourseService;

    @Autowired
    RedisTemplate<String,String> redisTemplate;

    @Autowired
    ModelMapper modelMapper;



    /**
     * 教师查看个人选择了该课程的学生名单
     */

    @GetMapping("/getStus")
    public Result<List<CourseOrder>> getTeacherAndCourseAndStudent(
            @RequestParam(value = "tid",required = false) int tid,
            @RequestParam(value = "cid",required = false) int cid
    ){
        List<CourseOrder> courseOrderList = courseOrderService.getTeacherAndCourseAndStudent(tid,cid);
        if(courseOrderList == null) return Result.error(CodeMsg.NULL_ANS);

        return new Result<>(courseOrderList);
    }

    @GetMapping("/getCourses")
    public Result<List<TeacherCourse>> getCourses(@RequestParam int tid){
        QueryWrapper<TeacherCourse>  queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("tid",tid);

        List<TeacherCourse> TeacherCourses = teacherCourseService.list(queryWrapper);
        if(TeacherCourses==null) return Result.error(CodeMsg.NULL_ANS);

        return new Result<>(TeacherCourses);
    }


}
